<template>
	<view class="content">
		<view class="cell-group list">
			<view class="cell-item" v-for="item in list" :key="item.article_id" @click="articleDetail(item.article_id)">
				<view class="cell-title-img"><image :src='item.image_input' mode="aspectFill"></image></view>
				<view class="cell-item-bd">
					<view class="article-title ">{{ item.title }}</view>
					<view class="article-time">{{ item.create_time }}</view>
				</view>
			</view>
		</view>
		<uni-load-more :status="loadStatus"></uni-load-more>
	</view>
</template>

<script>
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
export default {
	components: {
		uniLoadMore
	},
	data() {
		return {
			cid: 0, // 文章分类id
			page: 1,
			limit: 10,
			list: [],
			loadStatus: 'more',
			articleType: [],
			typeName: ''
		};
	},
	onLoad(e) {
		this.cid = e.id;
		var catname = '';

		uni.setNavigationBarTitle({
			title: catname
		});				
		this.articleList();
	},
	onReachBottom() {
		if (this.loadStatus === 'more') {
			this.articleList();
		}
	},
	methods: {
		redirect() {
			uni.navigateBack({
				delta: 1
			});
		},
		articleList() {
			let data = {
				page: this.page,
				limit: this.limit,
			};
			//console.log(this.cid);
			this.loadStatus = 'loading';
			this.$api.articleList(this.cid,data, res => {
				if (res.status) {
					uni.setNavigationBarTitle({
						title: res.data.list[0].articleCategory.title
					});
					const _list = res.data.list;
					this.list = [...this.list, ..._list];
					if (res.data.count > this.list.length) {
						this.loadStatus = 'more';
						this.page++;
					} else {
						// 数据已加载完毕
						this.loadStatus = 'noMore';
					}
				} else {
					// 接口请求出错了
					this.$common.errorToShow(res.msg);
				}
			});
		},
		selectType(id) {
			this.cid = id;
			this.$common.navigateTo('/pages/article/list?cid=' + id);
		},
		// 查看文章详情
		articleDetail(articleId) {
			this.$common.navigateTo('/pages/article/index?id=' + articleId + '&id_type=1');
		}
	}
};
</script>

<style>
.cell-title-img {
	width: 160upx;
	height: 160upx;
}

.cell-title-img image {
	width: 100%;
	height: 100%;
}

.cell-item-bd {
	padding-right: 0;
	vertical-align: top;
	position: relative;
	display: flex;
	flex: 1;
	flex-direction: column;
	align-items: baseline;
}

.article-title {
	font-size: 28upx;
	color: #333;
	width: 100%;
	min-height: 80upx;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
}

.article-time {
	font-size: 24upx;
	color: #999;
	display: inline-block;
	min-width: 220upx;
	min-height: 32upx;
	/* position: absolute; */
	/* bottom: 0; */
}

.flc {
	justify-content: flex-start;
	flex-wrap: wrap;
	padding: 10rpx 20rpx;
	border-bottom: 2rpx solid #f0f0f0;
}

.buttonStyle {
	margin: 0 15rpx 10rpx 0;
	padding: 6rpx 20rpx;
	border: 1rpx solid #ccc;
	font-size: 24rpx;
	border-radius: 10rpx;
}

.list {
	margin-bottom: 20rpx;
}

.navigationBar {
	position: fixed;
	left: 0;
	top: 0;
	width: 100%;
	height: 44px;
	padding: 7px 3px;
	text-align: center;
	// line-height: 44px;
	z-index: 998;
	color: #000;
	background-color: #fff;
	// position: relative;
	display: flex;
	justify-content: space-between;
}

.headerTitle {
	display: inline-block;
	font-weight: 700;
	font-size: 16px;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	line-height: 30px;
	width: 100%;
}

.navigationIcon {
	display: inline-block;
	// float: left;
	// margin-top: 10rpx;
	// overflow: hidden;
	display: flex;
	font-size: 27px;
	width: 30px;
}

.uni-btn-icon {
	color: #000;
	// font-size: 54rpx;
	// float: left;
	align-items: center;
}
</style>
